package gamagora.game
{
	import gamagora.box2d.OSPhysicData;
	import gamagora.game.utils.effect.Displacement;
	import gamagora.game.utils.effect.FXGroup;
	
	import org.flixel.FlxEmitter;
	import org.flixel.FlxG;
	import org.flixel.FlxGroup;
	import org.flixel.FlxParticle;
	import org.flixel.FlxSprite;

	public class OSFireWall extends OSWall
	{
		[Embed(source="embed/fire.png")]
		private static const FIRE:Class;
		
		private var _effectEmitter:Displacement;
		private var _group:FXGroup;
		private var _sprite:FlxSprite;
		private var _firstInit:Boolean;
		
		public function OSFireWall(x:Number=0, y:Number=0, w:Number=0, h:Number=0, nbParticles:uint = 10)
		{
			super(x, y, w, h, 0, OSPhysicData.FIRE_GROUND, true);
			makeGraphic(w, h, 0xff000000);
			
			_nbSprites = nbParticles;
			_firstInit = false;
			
			_group = new FXGroup();
			_group.add(_effectEmitter = new Displacement(_group.FXBuffer, x, y - 20));
			_effectEmitter.setSize(w, 1);
			_effectEmitter.setXSpeed(-5, 5);
			_effectEmitter.setYSpeed( -20, -60);
			_effectEmitter.blobHeight = 10;
			_effectEmitter.blobWidth = 6;
			_effectEmitter.displaceAmtX = 2;
			_effectEmitter.displaceAmtY = 3;
			_effectEmitter.alpha = .6;
			_effectEmitter.life = 0.5;
			_effectEmitter.blobCount = 300;
			_effectEmitter.begin();
			
			_sprite = new FlxSprite(x, y - h, FIRE);
			_nbSprites++;
		}
		
		public override function update():void
		{
			super.update();
			if(_inGame)
			{
				_group.update();
			}
		}
		
		public override function draw():void
		{
			_sprite.draw();
			super.draw();
			if(_inGame)
			{
				_group.draw();
			}
		}
		
		public override function destroy():void
		{
			super.destroy();
			_sprite.destroy();
			_group.destroy();
			_effectEmitter.destroy();
		}
	}
}
